package org.ragdollcat.secondaiagent.rag.factory;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.ai.rag.Query;
import org.springframework.ai.rag.preretrieval.query.transformation.QueryTransformer;
import org.springframework.ai.rag.preretrieval.query.transformation.RewriteQueryTransformer;
import org.springframework.stereotype.Component;

@Component
public class RewriteQueryTransformerFactory {

    private final QueryTransformer queryTransformer;


    public RewriteQueryTransformerFactory(ChatModel dashscopeChatModel){
        ChatClient.Builder builder = ChatClient.builder(dashscopeChatModel);
        queryTransformer = RewriteQueryTransformer.builder()
                .chatClientBuilder(builder)
                .build();
    }
    
    public Query getRewriteQuery(String text){
        return queryTransformer.transform(new Query(text));
    }
}
